﻿using System;
using System.Web;
using Gaia.Alp.Dependency.Castle;

namespace Dexter.Dependency.Castle {
	/// <summary>
	/// 	Concrete class to create IoC Engine
	/// </summary>
	public class CastleContainerFactory : IDexterContainerFactory {
		#region IAlpContainerFactory Members

		/// <summary>
		/// 	Creates this instance.
		/// </summary>
		/// <returns>An instance of the Container</returns>
		public IDexterContainer Create ( ) {
			return Create ( null );
		}

		public IDexterInstaller CreateInstaller ( ) {
			return new CastleInstaller ( );
		}

		/// <summary>
		/// 	Creates this instance.
		/// </summary>
		/// <param name = "configuration">The configuration.</param>
		/// <returns>An instance of the Container</returns>
		public IDexterContainer Create ( string configuration ) {
			var container = new CastleContainer ( );
			if ( !String.IsNullOrEmpty ( configuration ) ) {
				configuration = HttpContext.Current != null
				                	? HttpContext.Current.Server.MapPath ( configuration )
				                	: string.Concat ( AppDomain.CurrentDomain.BaseDirectory , configuration.Replace ( "~/" , string.Empty ) );
			}

			container.Configure ( configuration );

			return container;
		}

		#endregion
	}
}